package com.cykj.service;

import com.cykj.dto.ResponseDTO;
import com.cykj.mapper.UserMapper;
import com.cykj.pojo.CyGood;
import com.cykj.pojo.Good;
import com.cykj.pojo.GoodClass;
import com.cykj.pojo.GoodClassType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private RedisTemplate redisTemplate;
@Autowired
    private UserMapper userMapper;
    @Override
    public ResponseDTO getGoodClass() {
        List<GoodClass> goodClass=userMapper.getGoodClass();
        if(goodClass!=null){
            return ResponseDTO.success(goodClass);
        }
        else{
            return ResponseDTO.error("获取失败");
        }
    }

    @Override
    public ResponseDTO getGoodClassType(String id) {
        List<GoodClassType> goodClassTypes=userMapper.getGoodClassType(id);
        if(goodClassTypes!=null){
            return ResponseDTO.success(goodClassTypes);
        }
        else{
            return ResponseDTO.error("获取失败");
        }
    }
    @Override
    public ResponseDTO getHotGoods() {
        List<CyGood> hotGoods=userMapper.getHotGoods();
//        for (CyGood hotGood : hotGoods) {
//            redisTemplate.opsForValue().set("hotGood:"+ hotGood.getId(),hotGood);
//            redisTemplate.opsForValue().set("stock"+hotGood.getId(),hotGood.getGoodStock());
//            redisTemplate.opsForList().leftPush("hotList",hotGood);
//        }
        return ResponseDTO.success(userMapper.getHotGoods());
    }
    @Override
    public ResponseDTO getGoods(String id) {
        List<Good> goods=userMapper.getGoods(id);
        if(goods!=null){
            return ResponseDTO.success(goods);
        }
        else{
            return ResponseDTO.error("获取失败");
        }
    }
}
